const {Configuration} = require("webpack")
const path = require("path")

const {CleanWebpackPlugin} = require("clean-webpack-plugin")

const HtmlWebpackPlugin = require("html-webpack-plugin")

const CopyWebpackPlguin = require("copy-webpack-plugin")

const RemoveCommentsPlugin = require("./lx-remove-commonts-plugin")

/**
 * @type {{output: {path: string, filename: string}, devServer: {proxy: {"/api": {changeOrigin: boolean, pathRewrite: {"^/api": string}, target: string}}, open: boolean}, mode: string, entry: string, plugins: (CleanWebpackPlugin|HtmlWebpackPlugin|CopyPlugin)[], module: {rules: [{test: RegExp, use: string[]},{test: RegExp, use: string[]},{test: RegExp, use: {loader: string, options: {presets: string[]}}}]}}}
 */
const config = {
    entry: "./src/index.js",
    output: {
        filename: "bundle.js",
        path: path.join(__dirname, "dist")
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    'style-loader', 'css-loader'
                ]
            },
            {
                test: /\.md$/,
                use: ["html-loader", "./lx-markdown-loader"]
            },
            {
                test: /\.js$/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ["@babel/preset-env"]
                    }
                }
            }
        ]
    },
    plugins: [new CleanWebpackPlugin(), new HtmlWebpackPlugin({
        title: "lx牛逼",
        meta: {
            viewport: "width=device-width"
        },
        filename: "index.html",
        template: "./template.html",
        name: "lpx"
    }),
        new HtmlWebpackPlugin({
            title: "lsq牛逼",
            meta: {
                viewport: "width=device-width"
            },
            filename: "lsq.html",
            template: "./template.html",
            name: "lsq"
        }),
        new CopyWebpackPlguin({
            patterns: ["public"]
        }),
        // new RemoveCommentsPlugin()
    ],

    devServer: {
        proxy: {
            "/api": {
                target: "https://gitee.com",
                pathRewrite: {
                    '^/api': ""
                },
                changeOrigin: true
            }
        },
        open: true,
        hot: true,
        // static: ["public"]
    },
    devtool: "eval",
    optimization: {
        usedExports: true,
        minimize: false,
        concatenateModules: true,
        sideEffects: true
    },
    mode: "none"
}

module.exports = config